package de.hauschild.gmltracer.gml.impl.binding;

import de.hauschild.gmltracer.gml.Environment;
import de.hauschild.gmltracer.gml.Token;
import de.hauschild.gmltracer.gml.TokenStack;
import de.hauschild.gmltracer.gml.impl.AbstractToken;

/**
 * A {@link IdentifierToken} binds a concrete {@link Token} in {@link Environment} by name.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
public class IdentifierToken extends AbstractToken {

  private final String name;

  /**
   * Instantiates a new identifier token.
   * 
   * @param theName
   *          the name
   */
  public IdentifierToken(final String theName) {
    name = theName;
  }

  @Override
  public void evaluate(final Environment environment, final TokenStack tokenStack) {
    final Token token = environment.get(name);
    tokenStack.push(token.cloneToken());
  }

  /**
   * Gets the name.
   * 
   * @return the name
   */
  public String getName() {
    return name;
  }

  @Override
  public String toString() {
    return name;
  }
}
